package com.cn.zengzeng.spbzengzeng.service.sort;

import com.cn.zengzeng.spbzengzeng.po.NodeTree;


/**
 * @Description:
 * @Author: ZhangZengZeng
 * @Date: 2022/6/30 14:19
 */
public class TreeSort {
    public static void main (String[] args) {
        NodeTree g = new NodeTree("G",null,null);

        NodeTree e = new NodeTree("E",null,null);

        NodeTree f = new NodeTree("F",null,null);

        NodeTree d = new NodeTree("D",null,g);
        
        NodeTree b = new NodeTree("B",d,e);

        NodeTree c = new NodeTree("C",null,f);

        NodeTree a = new NodeTree("A",b,c);
        System.out.println("生成的二叉树：");

        System.out.println("            A");

        System.out.println("            |     ");

        System.out.println("       |---------|");

        System.out.println("       B         C");

        System.out.println("       |         |");

        System.out.println("  |---------|     -----|");

        System.out.println("  D         E          F");

        System.out.println("  |");

        System.out.println("   ----|");

        System.out.println("       G");
        preOrderTraversal(a );
        System.out.println();
        inOrderTraversal(a);
        System.out.println();
        poseOrderTraversal(a);
    }

    //前序遍历
    public static void preOrderTraversal(NodeTree root) {
        if (root == null) {
            return;
        } else {
            System.out.print("前序遍历"+root.getData() + " ");
            preOrderTraversal(root.getLeftTreeNode());
            preOrderTraversal(root.getRightTreeNode());
        }
    }
    //中序遍历
    public static void inOrderTraversal(NodeTree root) {
        if (root == null) {
            return;
        } else {
            inOrderTraversal(root.getLeftTreeNode());
            System.out.print("中序遍历"+root.getData() + " ");
            inOrderTraversal(root.getRightTreeNode());
        }
    }
    //后序遍历
    public static void poseOrderTraversal(NodeTree root) {
        if (root == null) {
            return;
        } else {
            poseOrderTraversal(root.getLeftTreeNode());
            poseOrderTraversal(root.getRightTreeNode());
            System.out.print("后序遍历"+root.getData() + " ");
        }
    }

}
